import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import axios from 'axios'

export default new Vuex.Store({
  state: {
    token: null,
  },
  getters: {},
  mutations: {
    setToken(state, token) {
      state.token = token
    },
  },
  actions: {
    loginAsync(context, formData) {
      // console.log(formData);
      axios
        .post('http://47.121.191.229/api/log', formData)
        .then(function (response) {
          console.log(response)
          if (response.status == 200 && response.data.code == '00000') {
            // context.commit(response.data.token)
            context.commit('setToken', response.data.token)
          }
        })
        .catch(function (error) {
          console.log(error)
        })
    },
  },
  modules: {},
})
